package com.totoro.tygeneratedragonblock.executor.action.impl;

import com.totoro.tygeneratedragonblock.constants.ActionConst;
import com.totoro.tygeneratedragonblock.data.ComputeResult;
import com.totoro.tygeneratedragonblock.executor.action.ActionExecutor;
import com.totoro.tygeneratedragonblock.utils.PapiUtil;
import com.totoro.tygeneratedragonblock.utils.StrUtil;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;

import java.util.Map;

public class ActionBarActionExecutor implements ActionExecutor {
    @Override
    public void execute(Map<String, ComputeResult> parseValueMap, String actionText, Player player) {
        actionText = parseValueMap(parseValueMap, actionText);
        if(null == actionText) {
            return;
        }
        actionText = StrUtil.getPrefixAfter(actionText, ActionConst.ACTION_BAR);
        actionText = PapiUtil.parseStrPapiVariable(player, actionText);
        player.spigot().sendMessage(
                ChatMessageType.ACTION_BAR,
                TextComponent.fromLegacyText(actionText)
        );
    }
}
